Skip to content

[#99] Import ContentLayout.json into the analyze database#101

Merged
SkowronskiAndrew merged 5 commits into
mainfrom
issue99-contentlayout-import
Jul 16, 2026
Merged

[#99] Import ContentLayout.json into the analyze database#101
SkowronskiAndrew merged 5 commits into
mainfrom
issue99-contentlayout-import

Conversation

@SkowronskiAndrew

Copy link
Copy Markdown
Collaborator

Summary

Part of #99 (first of two PRs; a follow-up adds reference resolution and input validation).

ContentDirectory builds name every output file by content hash, so an analyze database built from them can't be traced back to source assets. ContentLayout.json (written by BuildPipeline.BuildContentDirectory into the build report directory) carries that mapping — source assets, file-to-file dependencies, loadables, and artifact sizes. This PR imports it into the analyze database as a set of content_layout* tables and views, making the layout queryable with SQL. This is useful on its own for large layouts, and it is also the foundation the follow-up PR builds on to resolve references between Content Files.

Changes

Analyzer

  • New ContentLayoutParser (ISQLiteFileParser), detected by the exact filename ContentLayout.json (Unity always writes that name, so no content sniffing is needed). Unsupported schema versions fail with a clear error, and only a single layout per database is accepted.
  • New ContentLayoutSQLWriter + command classes + SQL resources, following the Addressables build layout import pattern: tables and views are created lazily on the first import, so analyzing AssetBundles or Player builds doesn't add empty tables; population runs in one transaction, with indexes created afterwards for large-layout performance.
  • The schema mirrors the json structure (content_layout_serialized_files, _source_assets, _serialized_file_dependencies with an order-preserving position column, _loadable_objects, _loadable_scenes, _binary_artifacts, _artifact_references, …), with two adjustments for natural querying: json sentinels (-1, missing content hash) become SQL NULL, and the top-level RootAssets list is folded into an is_root_asset flag.
  • Six convenience views join the pieces together, e.g. content_layout_source_assets_view (source asset → built files) and content_layout_data_files_view (the .resS/.resource data files each serialized file uses).
  • content_layout_serialized_files.serialized_file links to the core serialized_files table; it stays NULL in this PR and is populated by the follow-up PR when the build content is analyzed together with the layout.

Documentation

  • analyzer.md: schema reference for the new tables and views.

Testing

  • dotnet test — full suite green (734 passed).
  • New AnalyzeContentLayoutTests covers a layout-only analyze of the LeadingEdge ContentDirectory reference build: header row, per-table row counts, spot checks (built-in entry, dependency ordering, root-asset flag, derived filenames), view joins, the on-demand table creation (no content_layout tables when analyzing AssetBundles), the unsupported-version error, and the single-layout guard.
  • Manually verified the import with the sqlite3 CLI against the reference ContentLayout.json.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support in the Analyzer pipeline for importing Unity ContentDirectory ContentLayout.json into the analyze SQLite database, so ContentDirectory layouts become queryable via dedicated content_layout* tables and convenience views (foundation for later reference resolution work in #99 follow-up).

Changes:

  • Introduces a new ContentLayoutParser (ISQLiteFileParser) + ContentLayoutSQLWriter to import ContentLayout.json into new content_layout* tables/views (created lazily only when a layout is imported).
  • Adds SQL resources (tables, views, indexes) and command classes to populate the schema efficiently (single transaction + indexes created after inserts).
  • Adds tests covering layout-only imports, on-demand schema creation, unsupported versions, and the “single layout per DB” guard; updates analyzer schema documentation.

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
UnityDataTool.Tests/AnalyzeContentLayoutTests.cs Adds integration tests validating layout-only import behavior and schema/view expectations.
Documentation/analyzer.md Documents the new content_layout* tables and convenience views in the analyzer schema reference.
Analyzer/SQLite/Writers/ContentLayoutSQLWriter.cs Implements transactional population of the ContentLayout schema and deferred index creation.
Analyzer/SQLite/Parsers/ContentLayoutParser.cs Adds file detection for ContentLayout.json, version/uniqueness checks, and import orchestration.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayout.cs Adds insert command + DDL hook for the content_layout identity table.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutSerializedFile.cs Adds insert command + DDL hook for content_layout_serialized_files.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutSourceAsset.cs Adds insert command + DDL hook for content_layout_source_assets.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutSerializedFileDependency.cs Adds insert command + DDL hook for content_layout_serialized_file_dependencies.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutLoadableDependency.cs Adds insert command + DDL hook for content_layout_loadable_dependencies.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutLoadableSceneDependency.cs Adds insert command + DDL hook for content_layout_loadable_scene_dependencies.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutLoadableObject.cs Adds insert command + DDL hook for content_layout_loadable_objects.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutLoadableScene.cs Adds insert command + DDL hook for content_layout_loadable_scenes.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutBinaryArtifact.cs Adds insert command + DDL hook for content_layout_binary_artifacts.
Analyzer/SQLite/Commands/ContentLayout/AddContentLayoutArtifactReference.cs Adds insert command + DDL hook for content_layout_artifact_references.
Analyzer/Resources/ContentLayout.sql Defines the content_layout identity table DDL.
Analyzer/Resources/ContentLayoutSerializedFiles.sql Defines the serialized-files table DDL keyed by layout file_index.
Analyzer/Resources/ContentLayoutSourceAssets.sql Defines the source-assets table DDL.
Analyzer/Resources/ContentLayoutSerializedFileDependencies.sql Defines the serialized-file dependency edges DDL with order-preserving position.
Analyzer/Resources/ContentLayoutLoadableDependencies.sql Defines the loadable-object dependency table DDL.
Analyzer/Resources/ContentLayoutLoadableSceneDependencies.sql Defines the loadable-scene dependency table DDL.
Analyzer/Resources/ContentLayoutLoadableObjects.sql Defines the loadable-objects table DDL including is_root_asset and dropped-file sentinel mapping.
Analyzer/Resources/ContentLayoutLoadableScenes.sql Defines the loadable-scenes table DDL.
Analyzer/Resources/ContentLayoutBinaryArtifacts.sql Defines the binary-artifacts table DDL for artifact sizes/categories/hashes.
Analyzer/Resources/ContentLayoutArtifactReferences.sql Defines the artifact reference-edges table DDL.
Analyzer/Resources/ContentLayoutViews.sql Defines convenience views joining layout tables and core analyzer tables.
Analyzer/Resources/ContentLayoutIndexes.sql Defines post-import indexes for query performance on large layouts.
Analyzer/Properties/Resources.resx Registers the new SQL resource files for embedding.
Analyzer/Properties/Resources.Designer.cs Adds generated accessors for the new embedded SQL resources.
Analyzer/AnalyzerTool.cs Registers ContentLayoutParser in the parser list so it’s recognized during analyze runs.
Files not reviewed (1)
  • Analyzer/Properties/Resources.Designer.cs: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Analyzer/Resources/ContentLayoutViews.sql
Comment thread Analyzer/Resources/ContentLayoutViews.sql Outdated
Comment thread Analyzer/Resources/ContentLayoutViews.sql Outdated
Comment thread Analyzer/SQLite/Parsers/ContentLayoutParser.cs
Comment thread Documentation/analyzer.md Outdated
@SkowronskiAndrew
SkowronskiAndrew marked this pull request as ready for review July 16, 2026 19:47
@SkowronskiAndrew
SkowronskiAndrew merged commit ee9fda8 into main Jul 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants